<template>
  <div>
    <erpForm :props_cols="cols_data" :model="formData" ref="formRef"> </erpForm>
  </div>
</template>
<script>
import erpForm from "@/components/erpform/erpform.vue";
import { cols_data, baseFormData } from "./_utils";
import { cloneDeep as deepClone } from "lodash-es";
import { alertWithPaylod } from "@/utils/alertUtils";
import axios from "axios";
export default {
  components: {
    erpForm,
  },
  data() {
    return {
      cols_data,
      formData: deepClone(baseFormData),
    };
  },
  methods: {
    initByDialog(_data) {
      if (_data && _data.id) {
        this.formData = _data;
        this.$refs["formRef"].initByDialog({ formData: this.formData });
      }
    },
    async submitByDialog() {
      var paramsresult = this.$refs["formRef"].submitByDialog();
      if (!paramsresult?.success) {
        return paramsresult;
      }
      var parmas = paramsresult?.data;
      var resylt = await axios
        .post("/api/<%=tableName%>/apis", {
          _name: "addorupdate",
          ...parmas,
        })
        .then((res) => res.data);
      console.log("resylt :", resylt);
      alertWithPaylod(resylt);

      return resylt;
    },
  },
};
</script>
